898B - Proper Nutrition - CodeForces Solution


brute force implementation number theory *1100

Please click on ads to support us..

Python Code:

n, a, b = int(input()), int(input()), int(input())
o = 0
for x in range(n+1):
    y = (n - (x*a))/b
    if y.is_integer() == True and y >= 0:
        o += 1
        print("YES")
        print(x, int(y))
        break
if o != 1:
    print("NO")

C++ Code:

#include <bits/stdc++.h>
#include <numeric>
using namespace std;
using namespace std;
#define Gh ::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int>> vov;
typedef vector<ll> vl;
typedef pair<int, int> pi;
#define F first
#define S second
#define PB push_back
#define loop(i,a,b) for (int i = a; i < b; i++)
#define endl  "\n"
#define NO cout <<"NO\n"
#define YES cout << "YES\n"
#define nax 100005
#define LFT p<<1, L, (L+R)>>1
#define RGT p<<1|1, ((L+R)>>1)+1, R
#define all(x) 		x.begin(), x.end()
#define rall(v)	v.rbegin(), v.rend()
#define dmid  ll mid = L + ((R - L ) >> 1);
#define T int t; cin >> t; while (t--)
ll M = 1000000007;
ll mod(ll x) {
	return ((x % M + M) % M);
}
ll mul(ll a, ll b) {
	return mod(mod(a) * mod(b));
}
ll add(ll a, ll b) {
	return mod(mod(a) + mod(b));
}
ll dec(ll a, ll b) {
	return mod(mod(a) - mod(b));
}
int main()
{
	ll f = 0, n, a, b,x,y,s=0;
	cin >> n >> a >> b; if (b > a){swap(a, b);s=1;}
	for (ll i = 0; i < b; i++)
	{
		if ((n - a * i) % b == 0)
		{
			
			x = i;y=(n - a * i) / b;
			f = 1;
			break;
		}
	}
	if (f == 0||x<0||y<0)NO;
	else if(s) {
		YES;
		cout << y << " " << x;
	}
	else {
		YES;
		cout << x << " " << y;
	}
	return 0;
}


Comments

Submit
0 Comments
More Questions

1131F - Asya And Kittens
1475F - Unusual Matrix
133B - Unary
1547A - Shortest Path with Obstacle
624A - Save Luke
1238A - Prime Subtraction
1107C - Brutality
1391B - Fix You
988B - Substrings Sort
312A - Whose sentence is it
513A - Game
1711E - XOR Triangle
688A - Opponents
20C - Dijkstra
1627D - Not Adding
893B - Beautiful Divisors
864B - Polycarp and Letters
1088A - Ehab and another construction problem
1177B - Digits Sequence (Hard Edition)
1155B - Game with Telephone Numbers
1284A - New Year and Naming
863B - Kayaking
1395B - Boboniu Plays Chess
1475D - Cleaning the Phone
617B - Chocolate
1051B - Relatively Prime Pairs
95B - Lucky Numbers
1692D - The Clock
1553D - Backspace
1670D - Very Suspicious